package com.wanghao.utils;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileUtils {

	static public String ReadFile(File aFile) throws Exception {
		DataInputStream stream = new DataInputStream(new FileInputStream(aFile));
		int size = (int) aFile.length();

		byte[] buf = new byte[size];
		stream.readFully(buf);
		stream.close();

		String buffer = new String(buf, "utf-8");
		return buffer;
	}

	static public void WriteFile(File aFile, String aContent) throws Exception {
		DataOutputStream stream = new DataOutputStream(new FileOutputStream(
				aFile));
		stream.writeBytes(aContent);
		stream.close();
	}

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		File f = new File(
				"D:\\myproject\\openSource\\symbian-rss-helper\\trunk\\data\\bundle1\\data1.txt");
		String buf = FileUtils.ReadFile(f);
		DebugUtils.Output(buf);

		f = new File(
				"D:\\myproject\\openSource\\symbian-rss-helper\\trunk\\data\\bundle1\\data1.txt.output");
		FileUtils.WriteFile(f, buf);
	}

}
